library universal_platform;

import 'src/universal_platform_locator.dart' if (dart.library.io) 'src/platform_io.dart';

export 'src/universal_platform_locator.dart' if (dart.library.io) 'src/platform_io.dart';

abstract class UniversalPlatform {
  static UniversalPlatformType get value {
    try {
      return currentUniversalPlatform;
    } catch (e) {
      // Fallback to web if there's an issue
      return UniversalPlatformType.Web;
    }
  }

  static bool get isWeb {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Web;
    } catch (e) {
      return true; // Default to web if there's an issue
    }
  }
  static bool get isMacOS {
    try {
      return currentUniversalPlatform == UniversalPlatformType.MacOS;
    } catch (e) {
      return false;
    }
  }
  static bool get isWindows {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Windows;
    } catch (e) {
      return false;
    }
  }
  static bool get isLinux {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Linux;
    } catch (e) {
      return false;
    }
  }
  static bool get isAndroid {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Android;
    } catch (e) {
      return false;
    }
  }
  static bool get isIOS {
    try {
      return currentUniversalPlatform == UniversalPlatformType.IOS;
    } catch (e) {
      return false;
    }
  }
  static bool get isFuchsia {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Fuchsia;
    } catch (e) {
      return false;
    }
  }
  static bool get isOhos {
    try {
      return currentUniversalPlatform == UniversalPlatformType.Ohos;
    } catch (e) {
      return false;
    }
  }

  static bool get isApple => UniversalPlatform.isIOS || UniversalPlatform.isMacOS;
  static bool get isMobile => UniversalPlatform.isIOS || UniversalPlatform.isAndroid;
  static bool get isDesktop => isLinux || isMacOS || isWindows;
  static bool get isDesktopOrWeb => UniversalPlatform.isDesktop || UniversalPlatform.isWeb;

  static String get operatingSystem {
    try {
      switch (value) {
        case UniversalPlatformType.Web:
          return "web";
        case UniversalPlatformType.MacOS:
          return "macos";
        case UniversalPlatformType.Windows:
          return "windows";
        case UniversalPlatformType.Linux:
          return "linux";
        case UniversalPlatformType.Android:
          return "android";
        case UniversalPlatformType.IOS:
          return "ios";
        case UniversalPlatformType.Fuchsia:
          return "fuchsia";
        case UniversalPlatformType.Ohos:
          return "ohos";
      }
    } catch (e) {
      return "web"; // Default fallback
    }
  }
}

enum UniversalPlatformType {
  Web,
  Windows,
  Linux,
  MacOS,
  Android,
  Fuchsia,
  IOS,
  Ohos
}
